package com.gitee.zycra.union.api.common.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zycra
 */
public enum CommonResultEnum implements CommonEnum<CommonResultEnum> {

    /**
     * 公用返回码
     */
    SUCCESS(0, null),
    FAILED(1, "failed"),
    EXCEPTION(-1, "system error");

    private final Integer code;

    private final String desc;

    CommonResultEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    private static final Map<Integer, CommonResultEnum> MAP = new HashMap<>();

    static {
        for (CommonResultEnum value : CommonResultEnum.values()) {
            MAP.put(value.getCode(), value);
        }
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    public static CommonResultEnum getByCode(Integer code) {
        return MAP.get(code);
    }
}
